import React, { forwardRef } from 'react';
import * as DialogPrimitive from '@radix-ui/react-dialog';

// Dialog组件
const Dialog = DialogPrimitive.Root;

// DialogTrigger组件
const DialogTrigger = DialogPrimitive.Trigger;

// DialogPortal组件
const DialogPortal = DialogPrimitive.Portal;

// DialogOverlay组件
const DialogOverlay = forwardRef<HTMLDivElement, DialogPrimitive.DialogOverlayProps>(({ className, ...props }, ref) => (
  <DialogPrimitive.Overlay
    ref={ref}
    className={`fixed inset-0 z-50 bg-black/50 backdrop-blur-sm data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 ${className}`}
    {...props}
  />
));

// DialogContent组件
const DialogContent = forwardRef<HTMLDivElement, DialogPrimitive.DialogContentProps>(({ className, ...props }, ref) => (
  <DialogPrimitive.Content
    ref={ref}
    className={`fixed left-1/2 top-1/2 z-50 w-full max-w-md -translate-x-1/2 -translate-y-1/2 rounded-lg border bg-background p-6 shadow-lg data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 sm:max-w-lg ${className}`}
    {...props}
  />
));

// DialogHeader组件
const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
  <div className={`flex flex-col space-y-2 text-center sm:text-left ${className}`} {...props} />
);

// DialogTitle组件
const DialogTitle = forwardRef<HTMLHeadingElement, DialogPrimitive.DialogTitleProps>(({ className, ...props }, ref) => (
  <DialogPrimitive.Title
    ref={ref}
    className={`text-xl font-semibold leading-none tracking-tight ${className}`}
    {...props}
  />
));

// DialogDescription组件
const DialogDescription = forwardRef<HTMLParagraphElement, DialogPrimitive.DialogDescriptionProps>(({ className, ...props }, ref) => (
  <DialogPrimitive.Description
    ref={ref}
    className={`text-sm text-muted-foreground ${className}`}
    {...props}
  />
));

// DialogFooter组件
const DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
  <div className={`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2 ${className}`} {...props} />
);

// DialogClose组件
const DialogClose = DialogPrimitive.Close;

// 导出所有组件
export {
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogOverlay,
  DialogPortal,
  DialogTitle,
  DialogTrigger,
};